﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using compshop.Infrastructure;
using compshop.Infrastructure.CompShopDataService;

namespace compshop.Modules.ListOfEmployees
{
    /// <summary>
    /// Логика взаимодействия для EditEmployee.xaml
    /// </summary>
    public partial class EditEmployeeView : Window
    {
       void Initialize()
        {
            InitializeComponent();
            DataContext = this;
            gender = new Dictionary<byte,string>();
            gender.Add(1,"Male");
            gender.Add(2,"Female");
           CompShopEntities context= CompShopEntitiesContext.GetInstance();
           positions = context.Positions.ToList();
           departments = context.Departments.ToList();
           btnCancel.Click += new RoutedEventHandler(btnCancel_Click);
           btnOk.Click += new RoutedEventHandler(btnOk_Click);
        }

       void btnOk_Click(object sender, RoutedEventArgs e)
       {
           DialogResult = true;
           DateTime dateTemp;
           employee.Address = txbAddress.Text;
           bool rez = DateTime.TryParse(txbBirthDate.Text, out dateTemp);
           if (rez)
               employee.BirthDate = dateTemp;
           else MessageBox.Show("Дата рождения не введена или неправильно введена.");
           employee.Code =int.Parse(txbCode.Text);
           employee.Department =(Department) cbxDepartment.SelectedItem;
           employee.DepartmentID = employee.Department.DepartmentID;
           rez= DateTime.TryParse(txbDismissingDate.Text, out dateTemp);
           if (rez)
               employee.DismissingDate = dateTemp;
           employee.FirstName = txbFName.Text;
           employee.Gender =(byte) txbGender.SelectedValue;
           rez = DateTime.TryParse(txbHiringDate.Text, out dateTemp);
           if (rez)
               employee.HiringDate = dateTemp;
           else MessageBox.Show("Дата приема на работу не введена или неправильно введена.");
           employee.IdentificationNumber = txbIdentificationNumber.Text;
           employee.LastName = txbLName.Text;
           employee.Login = txbLogin.Text;
           employee.MiddleName = txbMiddleName.Text;
           employee.PassportNumber = txbPassportNumber.Text;
           employee.PassportSeries = txbPassportSeries.Text;
           employee.Password = txbPassword.Text;
           employee.Phone = txbPhone.Text;
           employee.Position = (Position)cbxPosition.SelectedItem;
           employee.PositionID = employee.Position.PositionID;
           this.Close();
       }

       void btnCancel_Click(object sender, RoutedEventArgs e)
       {
           DialogResult = false;
           this.Close();
       }
        public EditEmployeeView()
        {
            employee = new Employee();
            Initialize();
            
        }
        public EditEmployeeView(Employee editingEmployee)
        {
            employee = editingEmployee;
            Initialize();
             
        }
        public Employee employee { get; set; } 
        public Dictionary<byte,String> gender {get; set;}
        public List<Position> positions { get; set; }
        public List<Department> departments { get; set; }
    }
}
